package com.seveneight.baijiesteward.ui.main.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.seveneight.baijiesteward.R;
import com.seveneight.baijiesteward.adapter.SelectTableAdapter;
import com.seveneight.baijiesteward.base.BaseActivity;
import com.seveneight.baijiesteward.bean.AnyBean;
import com.seveneight.baijiesteward.bean.BankListBean;
import com.seveneight.baijiesteward.http.MyCallBack;
import com.seveneight.baijiesteward.ui.user.model.SeleCardTagListModel;
import com.seveneight.baijiesteward.utils.ToastUtil;
import com.seveneight.baijiesteward.views.cover.MyListView;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class SelectThemeActivity extends BaseActivity implements View.OnClickListener{

    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.table_list)
    MyListView listView;
    SelectTableAdapter mAdapter;
    List<BankListBean> listData=new ArrayList<>();
    List<BankListBean> seleData=new ArrayList<>();
    SeleCardTagListModel model;

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_select_theme);
    }

    @Override
    protected void initView() {
        mAdapter=new SelectTableAdapter(this,listData);
        listView.setAdapter(mAdapter);
    }

    @Override
    protected void initData() {
        tv_title.setText("选择标签");
        model=new SeleCardTagListModel();
        model.getBankList(this, jsonFormat.commonParam(), new MyCallBack<AnyBean>() {
            @Override
            public void onSuccess(AnyBean anyBean) {
                listData= JSON.parseArray(anyBean.getBankTagList(),BankListBean.class);
                mAdapter.refresh(listData);
            }

            @Override
            public void onFailed() {

            }
        });


    }

    @Override
    protected void setListener() {

    }
    public void setSeleData(BankListBean item){
        if (item.getSelect()){
            seleData.add(item);
        }
    }
    public void remore(BankListBean item){
        for (int i=0;i<seleData.size();i++){
            if (seleData.get(i).getId().equals(item.getId())){
                seleData.remove(i);
                break;
            }
        }
    }

    @OnClick({R.id.credit_bt_next,R.id.iv_back})
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.iv_back:
                finish();
                break;
            case R.id.credit_bt_next:
                if (seleData.size()==3){
                    Intent intent=new Intent();
                    intent.putExtra("selData", (Serializable) seleData);
                    setResult(RESULT_OK,intent);
                    finish();
                }
                break;
        }
    }
}
